// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

/*
*Hi, I'm Lin Dong,
*this shader is about Super Sampling Anti-Aliasing in unity3d
*if you want to get more detail please enter my blog http://blog.csdn.net/wolf96
*/
Shader "GJ/Merge" {
	Properties{
	_MainTex("MainTex", 2D) = "white" {}
	_Tex1("Tex1", 2D) = "white" {}
	_Tex2("Tex2", 2D) = "white" {}
	_Tex3("Tex3", 2D) = "white" {}

}
	SubShader{
        Tags {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
        }
        Cull Off Lighting Off ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0

            #include "UnityCG.cginc"

			sampler2D _MainTex;
			float4 _MainTex_ST;
            sampler2D _Tex1;
			sampler2D _Tex2;
			sampler2D _Tex3;

            struct a2v
            {
                float4 vertex : POSITION;
                fixed4 color  : COLOR;
                float2 uv     : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                float2 uv       : TEXCOORD0;
                UNITY_VERTEX_OUTPUT_STEREO
            };

			v2f vert(a2v v) {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.color = v.color;
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
			}
			float4 frag(v2f i) :COLOR
			{
                fixed4 tex = tex2D(_MainTex, i.uv);
				tex.r = 0;
				tex.g = 0;
				tex.b = 0;
				tex.a = 0;
                fixed4 tex1 = tex2D(_Tex1, i.uv);
				if (tex1.a > 0.1) return tex1;
                fixed4 tex2 = tex2D(_Tex2, i.uv);
				if (tex2.a > 0.1) return tex2;
                fixed4 tex3 = tex2D(_Tex3, i.uv);
				if (tex3.a > 0.1) return tex3;
				return tex;
			}
			ENDCG
		}

	}
}